using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace jogoLudumdare
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Fase1 fase1;
        Fase2 fase2;
        Fase3 fase3;
        Language language;
        Abertura abertura;
        Intro intro;
        Menu menu;
        MouseState mouse;
        Controles controles;
        Instrucoes instrucoes;
        SpriteFont Font;
        Credits credits;
        public static Texture2D FundoGanhaItem;
        private GameState gameState;
      

        public  enum EstadoIdioma
        {
            Ingles,
            Portugues
        }
        public static EstadoIdioma IdiomaAtual;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
           
        }

      
        protected override void Initialize()
        {

            gameState = GameState.Language;
            //gameState = GameState.Credits;
            IdiomaAtual = EstadoIdioma.Ingles;
            graphics.PreferredBackBufferHeight = 600;
            graphics.PreferredBackBufferWidth = 800;
            graphics.ApplyChanges();
            IsMouseVisible = true;
            base.Initialize();
        }

        
        protected override void LoadContent()
        {
          
            spriteBatch = new SpriteBatch(GraphicsDevice);
            fase1 = new Fase1(Content);
            fase2 = new Fase2(Content);
            fase3 = new Fase3(Content);
            language = new Language(Content);
            intro = new Intro(Content);
            menu = new Menu(Content);
            credits = new Credits(Content);
            abertura = new Abertura(Content);
            controles = new Controles(Content);
            instrucoes = new Instrucoes(Content);
            Font = Content.Load<SpriteFont>("font");
            FundoGanhaItem = Content.Load<Texture2D>("Fundo_Coleta");


           
        }

    
        protected override void UnloadContent()
        {
           
        }

       
        protected override void Update(GameTime gameTime)
        {

            mouse = Mouse.GetState();

            switch (gameState)
            {


                case GameState.Language:
                    language.Update(gameTime);
                    if (language.nextState == GameState.Abertura)
                    {
                        gameState = GameState.Abertura;
                        abertura.nextState = GameState.Abertura;
                    }
                    break;
                case GameState.Abertura:
                    abertura.Update(gameTime);
                    if (abertura.nextState == GameState.Menu)
                    {
                        gameState = GameState.Menu;
                        menu.nextState = GameState.Menu;
                    }
                    break;

                case GameState.Instrucoes:
                    instrucoes.Update(gameTime);
                    if (instrucoes.nextState == GameState.Controles)
                    {
                        gameState = GameState.Controles;
                        controles.nextState = GameState.Controles;
                    }
                    break;

                case GameState.Controles:
                    controles.Update(gameTime);
                    if (controles.nextState == GameState.Menu)
                    {
                        gameState = GameState.Menu;
                        menu.nextState = GameState.Menu;
                    }
                    break;

                case GameState.Intro:
                    intro.Update(gameTime);
                    if (intro.nextState == GameState.Fase1)
                    {
                        gameState = GameState.Fase1;
                        fase1.nextState = GameState.Fase1;
                    }
                    break;
                case GameState.Fase1:
                    fase1.Update(gameTime);
                    if (fase1.nextState == GameState.Fase2)
                    {
                        gameState = GameState.Fase2;
                        fase2.nextState = GameState.Fase2;
                    }
                    break;

                case GameState.Fase2:
                    fase2.Update(gameTime, mouse);
                    
                    if (fase2.nextState == GameState.Fase1)
                    {
                        gameState = GameState.Fase1;
                        fase1.nextState = GameState.Fase1;
                    }

                    if (fase2.nextState == GameState.Fase3)
                    {
                        gameState = GameState.Fase3;
                        fase3.nextState = GameState.Fase3;
                    }
                    break;

                case GameState.Fase3:
                    fase3.Update(gameTime, mouse);
                    if (fase3.nextState == GameState.Menu)
                    {
                        gameState = GameState.Menu;
                        menu.nextState = GameState.Menu;
                    }
                    if (fase3.nextState == GameState.Credits)
                    {
                        gameState = GameState.Credits;
                        credits.nextState = GameState.Credits;
                    }
                    break;
                case GameState.Menu:
                    menu.Update(gameTime);

                   
                    if (menu.nextState == GameState.Fase1)
                    {
                        gameState = GameState.Fase1;
                        fase1.nextState = GameState.Fase1;
                    }
                    if (menu.nextState == GameState.Intro)
                    {
                        gameState = GameState.Intro;
                        intro.nextState = GameState.Intro;
                    }

                    if (menu.nextState == GameState.Credits)
                    {
                        gameState = GameState.Credits;
                        credits.nextState = GameState.Credits;
                    }

                    if (menu.nextState == GameState.Instrucoes)
                    {
                        gameState = GameState.Instrucoes;
                        instrucoes.nextState = GameState.Instrucoes;
                    }
                    if (menu.nextState == GameState.Exit)
                    {
                        gameState = GameState.Exit;
                    }
                    break;

                case GameState.Credits:
                    credits.Update(gameTime);
                    if (credits.nextState == GameState.Menu)
                    {
                        gameState = GameState.Menu;
                        menu.nextState = GameState.Menu;
                    }
                  
                    break;
                case GameState.Exit:
                    this.Exit();
                    break;
            }

            
            
           

            base.Update(gameTime);
        }

       
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();
            switch (gameState)
            {

                case GameState.Language:
                    language.Draw(spriteBatch, mouse);
                    break;

                case GameState.Abertura:
                    abertura.Draw(spriteBatch, mouse);
                    break;

                case GameState.Intro:
                    intro.Draw(spriteBatch, mouse);
                    break;
                case GameState.Instrucoes:
                    instrucoes.Draw(spriteBatch, mouse);
                    break;
                case GameState.Controles:
                    controles.Draw(spriteBatch, mouse);
                    break;
                case GameState.Fase1:
                    fase1.Draw(spriteBatch, mouse);
                    break;

                case GameState.Fase2:
                    fase2.Draw(spriteBatch, mouse);
                    break;

                case GameState.Fase3:
                    fase3.Draw(spriteBatch, mouse);
                    break;

                case GameState.Menu:
                    menu.Draw(spriteBatch, mouse);
                    break;

                case GameState.Credits:
                    credits.Draw(spriteBatch, mouse);
                    break;
            }
            
            
            
          //  spriteBatch.DrawString(Font, "" + mouse.X, Vector2.Zero, Color.White);
           // spriteBatch.DrawString(Font, Convert.ToString(Intro.Contador), Vector2.Zero, Color.White);
           // spriteBatch.DrawString(Font, "" + mouse.Y, new Vector2(0, 15), Color.White);
            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
